import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import moment from 'moment';
import { getUserGoodsChangeUserMobileCode, payWayList } from './api';
import { vipcardList } from '@apps/ant-bus/src/views/business/goods/vipcard/data/api';
import { airportList } from '@apps/ant-bus/src/views/business/airport/data/api';
import { employeeList } from '@apps/ant-bus/src/views/business/employeeManage/employee/data/api';
import { employeeServerList } from '@apps/ant-bus/src/views/business/employeeManage/employeeserver/data/api';
import { xunLianPayParamList } from '@apps/ant-bus/src/views/business/payset/xunlianPayparam/api';
import { yinLianPayParamList } from '@apps/ant-bus/src/views/business/payset/yinlianPayparam/api';
import { fuIouPayParamList } from '@apps/ant-bus/src/views/business/payset/fuIouPayparam/api';
import { nongyePayparamList } from '@apps/ant-bus/src/views/business/payset/nongyePayparam/api';
import { listFullDeductionType } from '@apps/ant-bus/src/views/business/userManage/fullDeductionDetail/data/api';
import { companyList } from '@apps/ant-bus/src/views/business/companyManage/company/data/api';
import { rules } from '@pkg/utils';
import { RenderType } from '@pkg/setting';
import { weChatList } from '@apps/ant-bus/src/views/business/platformManage/wechat/data/api';

export const columns: BasicColumn[] = [
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
  {
    title: '会员账号',
    dataIndex: 'mainAccount',
    width: 120,
    isExport: false,
  },
  {
    title: '会员姓名',
    dataIndex: 'userName',
    width: 120,
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 120,
  },
  {
    title: '紧急手机号',
    dataIndex: 'telePhone',
    width: 120,
  },
  {
    title: '会员卡号',
    dataIndex: 'vipCardNo',
    width: 180,
  },
  {
    title: '证件类型',
    dataIndex: 'identityType',
    width: 120,
    dictData: [
      { label: '身份证', value: 1 },
      { label: '护照', value: 2 },
      { label: '回乡证(港澳台居民来往内地通行证)', value: 3 },
      { label: '台胞证', value: 4 },
      { label: '其他', value: 5 },
      { label: '军人证', value: 6 },
      { label: '外国居留身份证', value: 7 },
      { label: '港澳台居民居住证', value: 8 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '证件号码',
    dataIndex: 'identityNo',
    width: 180,
  },
  {
    title: '卡种名称',
    dataIndex: 'goodsName',
    width: 150,
  },
  {
    title: '贵宾厅服务有效期',
    dataIndex: 'viproomDate',
    width: 140,
  },
  {
    title: '是否开票',
    dataIndex: 'applyInvoiceState',
    width: 120,
    dictData: [
      { label: '未开票', value: 0 },
      { label: '已开票', value: 1, color: '#00ee28' },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '全额抵扣',
    dataIndex: 'fullDeduction',
    width: 100,
    dictData: [
      { label: '否', value: 0 },
      { label: '是', value: 1, color: '#00ee28' },
      { label: '退卡撤销', value: 2, color: '#f60606' },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '退款类型',
    dataIndex: 'refundSourceType',
    width: 120,
    dictData: [
      { label: '现办现退', value: 1, color: '#ee0303' },
      { label: '普通退卡', value: 2, color: '#032aee' },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '开卡日期',
    dataIndex: 'buyDate',
    width: 120,
  },
  {
    title: '支付金额',
    dataIndex: 'payAmount',
    width: 120,
  },
  {
    title: '销售姓名',
    dataIndex: 'employeeName',
    width: 120,
  },
  {
    title: '合卡销售',
    dataIndex: 'heKaRemark',
    width: 120,
  },
  {
    title: '退卡时间',
    dataIndex: 'refundDate',
    width: 150,
  },
  {
    title: '退款金额',
    dataIndex: 'refundAmount',
    width: 150,
  },
  {
    title: '开卡地',
    dataIndex: 'airportName',
    width: 120,
  },
  {
    title: '来源',
    dataIndex: 'sourceType',
    width: 120,
    dictData: [
      { label: '扫码注册', value: 1 },
      { label: '公众号购买', value: 2 },
      { label: '销售新增', value: 3 },
      { label: '后台新增', value: 4 },
      { label: '后台导入', value: 5 },
      { label: '礼品卡接收', value: 6 },
      { label: '后台批量生成', value: 7 },
      { label: '销售赠送', value: 8 },
      { label: '代理商下单', value: 9 },
      { label: '企业下单', value: 10 },
      { label: '后台券码生成', value: 11 },
      { label: '电子金兑换', value: 12 },
      { label: '合作方同步', value: 13 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '下单企业',
    dataIndex: 'companyName',
    width: 200,
  },
  {
    title: '收款方式',
    dataIndex: 'paywayName',
    width: 180,
  },
  {
    title: '微信支付Id',
    dataIndex: 'payInfoId',
    width: 170,
  },
  {
    title: '三方订单号',
    dataIndex: 'thirdOrderNo',
    width: 170,
  },
  {
    title: '渠道订单号',
    dataIndex: 'channelOrderNum',
    width: 340,
  },
  {
    title: '升降级卡种价格',
    dataIndex: 'upgradePayAmount',
    width: 120,
  },
  {
    title: '升降时间',
    dataIndex: 'upgradeDate',
    width: 150,
  },
  {
    title: '卡状态',
    dataIndex: 'vipCardState',
    width: 120,
    dictData: [
      { label: '待激活', value: 0 },
      { label: '正常', value: 1 },
      { label: '已过期', value: 2 },
      { label: '未开通', value: 3 },
      { label: '未通过', value: 4 },
      { label: '冻结', value: 5 },
      { label: '退卡中', value: 6 },
      { label: '已退卡', value: 7 },
      { label: '已转卡', value: 8 },
      { label: '已转赠', value: 9 },
      { label: '冻结（延时开通）', value: 10 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '未成年',
    dataIndex: 'haveAdult',
    width: 140,
    dictData: [
      { label: '已成年', value: 'haveAdult', color: '#00ee28' },
      { label: '未成年', value: 'noAdult', color: '#585b58' },
      { label: '未知', value: 'unKnowAdult', color: '#0f94d7' },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 180,
  },
  {
    title: '标签',
    dataIndex: 'newestTagRemark',
    width: 120,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'mainAccount',
    label: '会员账号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'userName',
    label: '姓名',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'mobile',
    label: '手机号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'payAmount',
    label: '开卡金额',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'ageType',
    label: '是否成年',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '已成年', value: 'haveAdult' },
        { label: '未成年', value: 'noAdult' },
        { label: '未知', value: 'unKnowAdult' },
      ],
    },
  },
  {
    field: 'vipCardNo',
    label: '卡号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'employeeName',
    label: '销售',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'payType',
    label: '收款方式',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: ({ formActionType, formModel }) => {
      return {
        options: [
          { label: '全部', value: '' },
          { label: '讯联微信', value: 'PAY_WX' },
          { label: '银联微信', value: 'PAY_WX_YINLIAN' },
          { label: '农业银行微信', value: 'PAY_WX_NONGYE' },
          { label: '富友微信', value: 'PAY_WX_FUIOU' },
          { label: '富友微信小程序', value: 'PAY_WX_FUIOU_MINI' },
          { label: '交通银行微信', value: 'PAY_WX_JIAOTONG' },
          { label: '线下支付', value: 'PAY_UNDERLINE' },
          { label: '扫码支付', value: 'PAY_QRCODE' },
        ],
        onChange: payType => {
          const { updateSchema } = formActionType;
          //所属部门修改后更新负责部门下拉框数据
          let componentProps = {};
          if (payType == 'PAY_WX' || payType == 'PAY_QRCODE') {
            componentProps = {
              api: xunLianPayParamList,
              labelField: 'paramName',
              valueField: 'xunlianPayparamId',
              immediate: true,
              showSearch: true,
            };
          }
          if (payType == 'PAY_WX_YINLIAN') {
            componentProps = {
              api: yinLianPayParamList,
              labelField: 'yinlianPayName',
              valueField: 'yinlianPayparamId',
              immediate: true,
              showSearch: true,
            };
          }
          if (payType == 'PAY_UNDERLINE') {
            componentProps = {
              api: payWayList,
              labelField: 'paywayName',
              valueField: 'paywayId',
              immediate: true,
              showSearch: true,
            };
          }
          if (payType == 'PAY_WX_FUIOU' || payType == 'PAY_WX_FUIOU_MINI') {
            componentProps = {
              api: fuIouPayParamList,
              labelField: 'fuIouParamName',
              valueField: 'fuIouPayParamId',
              immediate: true,
              showSearch: true,
            };
          }
          if (payType == 'PAY_WX_NONGYE') {
            componentProps = {
              api: nongyePayparamList,
              labelField: 'nongyeParamName',
              valueField: 'nongyePayParamId',
              immediate: true,
              showSearch: true,
            };
          }
          updateSchema([
            {
              field: 'targetPayParamId',
              componentProps: componentProps,
            },
          ]);
          formModel.targetPayParamId = null;
        },
      };
    },
  },
  {
    field: 'targetPayParamId',
    label: '支付通道',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      placeholder: '请先选择收款方式',
    },
  },
  {
    field: 'payInfoId',
    label: '支付Id',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'businessId',
    label: '业务Id',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'goodsIdArray',
    label: '卡种',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: vipcardList,
      params: { handlerName: 'busVipCardListHandler' },
      labelField: 'goodsName',
      valueField: 'goodsId',
      immediate: true,
      showSearch: true,
      mode: 'multiple',
    },
  },
  {
    field: 'airportIdArray',
    label: '开卡地',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: airportList,
      params: { handlerName: 'busAirportRoleListHandler' },
      labelField: 'airportName',
      valueField: 'airportId',
      immediate: true,
      showSearch: true,
      mode: 'multiple',
    },
  },
  {
    field: 'vipCardState',
    label: '状态',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '待激活', value: 0 },
        { label: '正常', value: 1 },
        { label: '已过期', value: 2 },
        { label: '未开通', value: 3 },
        { label: '未通过', value: 4 },
        { label: '冻结', value: 5 },
        { label: '退卡中', value: 6 },
        { label: '已退卡', value: 7 },
        { label: '已转卡', value: 8 },
        { label: '已转赠', value: 9 },
        { label: '冻结（延时开通）', value: 10 },
      ],
    },
  },
  {
    field: 'sourceType',
    label: '来源',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '扫码注册', value: 1 },
        { label: '公众号购买', value: 2 },
        { label: '销售新增', value: 3 },
        { label: '后台新增', value: 4 },
        { label: '后台导入', value: 5 },
        { label: '礼品卡接收', value: 6 },
        { label: '后台批量生成', value: 7 },
        { label: '销售赠送', value: 8 },
        { label: '代理商下单', value: 9 },
        { label: '企业下单', value: 10 },
        { label: '后台券码生成', value: 11 },
        { label: '电子金兑换', value: 12 },
        { label: '合作方同步', value: 13 },
      ],
    },
  },
  {
    field: 'applyInvoiceState',
    label: '是否开票',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '未开票', value: 0 },
        { label: '已开票', value: 1 },
      ],
    },
  },
  {
    label: '合作企业',
    field: 'companyId',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      api: companyList,
      labelField: 'companyName',
      valueField: 'companyId',
    },
  },
  {
    field: 'fullDeduction',
    label: '全额抵扣',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '否', value: 0 },
        { label: '是', value: 1 },
      ],
    },
  },
  {
    field: 'startDate',
    label: '开始日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'endDate',
    label: '结束日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'refundStartDate',
    label: '退卡开始日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'refundEndDate',
    label: '退卡结束日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'exportTimeType',
    label: '导出时间选择',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '按创建日期导出', value: 1 },
        { label: '按退卡日期导出', value: 2 },
      ],
    },
  },
];

export const delayFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    colProps: { span: 24 },
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'expireDate',
    label: '过期日期',
    component: 'Input',
    colProps: { span: 24 },
    required: false,
    dynamicDisabled: true,
  },
  {
    label: '延期至',
    field: 'newExpireDate',
    required: true,
    component: 'DatePicker',
    colProps: { span: 24 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
];

export const upgradeFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'oldGoodsId',
    label: '旧卡种',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '所属机场',
    field: 'airportId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: airportList,
        labelField: 'airportName',
        valueField: 'airportId',
        immediate: true,
        showSearch: true,
        onChange: airportId => {
          formModel.employeeId = null;
        },
      };
    },
  },
  {
    label: '销售',
    field: 'employeeId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      let airportId = formModel.airportId;
      return {
        api: employeeList,
        params: { handlerName: 'busEmployeeListHandler' },
        labelField: 'employeeName',
        valueField: 'employeeId',
        immediate: true,
        showSearch: true,
      };
    },
  },
  {
    field: 'goodsId',
    label: '选择卡种',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: vipcardList,
        params: {
          handlerName: 'busVipCardListHandler',
          isTiyan: 0,
          oldGoodsId: formModel.oldGoodsId,
          airportId: formModel.airportId,
        },
        labelField: 'newGoodsName',
        valueField: 'goodsId',
        immediate: false,
        showSearch: true,
      };
    },
  },
  {
    field: 'realPayAmount',
    label: '实际支付/退款金额',
    component: 'InputNumber',
    required: true,
    dynamicRules: () => rules.price(true),
    componentProps: {
      style: { width: '50%' },
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    required: false,
    componentProps: {
      placeholder: '请输入备注,原因等',
      rows: 2,
      maxLength: 200,
    },
  },
];

export const oldBackCardFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'userName',
    label: '会员姓名',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'refundReason',
    label: '退卡原因',
    component: 'InputTextArea',
    required: true,
  },
  {
    field: 'remark',
    helpMessage: '请把会员退卡相关信息在此备注说明',
    label: '退卡备注',
    component: 'InputTextArea',
    required: true,
  },
];

export const backCardFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'canRefundOriginal',
    label: '是否可以原路退款',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'payAmount',
    label: '支付金额',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'isUpgrade',
    label: '是否升降级过',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '退款方式',
    field: 'refundWay',
    component: 'RadioGroup',
    required: true,
    componentProps: ({ formModel }) => {
      let canRefundOriginal = formModel.canRefundOriginal;
      return {
        options: [
          { label: '银行卡退款', value: 'refund_bank' },
          { label: '线上原路退款', value: 'refund_original', disabled: canRefundOriginal != 1 },
        ],
      };
    },
  },
  {
    label: '承担方式',
    field: 'bearWay',
    component: 'RadioGroup',
    required: true,
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '会员同意全部承担', value: 1 },
        { label: '会员不同意全部承担', value: 2 },
      ],
    },
  },
  {
    label: '会员承担金额',
    field: 'vipBearAmount',
    component: 'InputNumber',
    required: true,
    componentProps: ({ formModel }) => {
      let payAmount = formModel.payAmount;
      return {
        min: 0,
        max: payAmount,
        onChange: value => {
          console.info(payAmount);
          formModel.refundAmount = Number((Number(payAmount) - Number(value)).toFixed(2));
        },
      };
    },
  },
  {
    label: '销售承担金额',
    field: 'saleBearAmount',
    component: 'InputNumber',
    defaultValue: 0,
    required: true,
  },
  {
    label: '退款金额',
    field: 'refundAmount',
    component: 'InputNumber',
    required: true,
    helpMessage: '退款金额将根据会员实际承担费用自动生成，系统不支持修改',
    componentProps: ({ formModel }) => {
      let isUpgrade = formModel.isUpgrade;
      console.info(isUpgrade);
      return {
        disabled: isUpgrade == 0,
        max: formModel.payAmount,
      };
    },
  },
  {
    field: 'bank',
    label: '银行名称',
    component: 'Input',
    required: ({ model, values }) => {
      if (values.refundWay == 'refund_bank') {
        return true;
      } else {
        return false;
      }
    },
    ifShow: ({ model, values }) => {
      if (values.refundWay == 'refund_bank') {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    field: 'bankNo',
    label: '银行卡号',
    component: 'Input',
    required: ({ model, values }) => {
      if (values.refundWay == 'refund_bank') {
        return true;
      } else {
        return false;
      }
    },
    ifShow: ({ model, values }) => {
      if (values.refundWay == 'refund_bank') {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    field: 'refundReason',
    label: '退卡原因',
    component: 'InputTextArea',
    required: true,
  },
  {
    field: 'remark',
    helpMessage: '请把会员退卡相关信息在此备注说明',
    label: '退卡备注',
    component: 'InputTextArea',
    required: true,
    componentProps: {
      placeholder: '请把会员退卡相关信息在此备注说明',
      rows: 2,
      maxLength: 200,
    },
  },
];

export const editEmployeeFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'mobile',
    label: '会员手机号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'employeeId',
    label: '所属销售',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      api: employeeList,
      params: { handlerName: 'busEmployeeListHandler' },
      labelField: 'employeeAccountName',
      valueField: 'employeeId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    field: 'airportId',
    label: '所属机场',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: airportList,
      labelField: 'airportName',
      valueField: 'airportId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    field: 'hekaEmployeeId',
    label: '合卡销售',
    helpMessage: '请选择合卡销售',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      api: employeeList,
      params: { handlerName: 'busEmployeeListHandler' },
      labelField: 'employeeName',
      valueField: 'employeeId',
      immediate: true,
      showSearch: true,
    },
  },
];

export const editPrivateDataFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'userName',
    label: '姓名',
    component: 'Input',
    required: true,
  },
  {
    field: 'lastName',
    label: '英文姓',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return [2, 3, 4, 7].includes(model.identityType);
    },
  },
  {
    field: 'firstName',
    label: '英文名',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return [2, 3, 4, 7].includes(model.identityType);
    },
  },
  {
    field: 'mobile',
    label: '会员手机号',
    component: 'Input',
    required: true,
  },
  {
    field: 'identityType',
    label: '证件类型',
    component: 'Select',
    required: true,
    defaultValue: 1,
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '身份证', value: 1 },
          { label: '护照', value: 2 },
          { label: '回乡证(港澳台居民来往内地通行证)', value: 3 },
          { label: '台胞证', value: 4 },
          { label: '其他', value: 5 },
          { label: '军人证', value: 6 },
          { label: '外国居留身份证', value: 7 },
          { label: '港澳台居民居住证', value: 8 },
        ],
        onChange: identityType => {
          console.info('identityType', identityType);
          if (identityType == 1) {
            formModel.lastName = null;
            formModel.firstName = null;
            formModel.nationality = null;
            formModel.sex = null;
            formModel.birthDate = null;
            formModel.issueAt = null;
            formModel.expiryDate = null;
          }
        },
      };
    },
  },
  {
    field: 'identityNo',
    label: '证件号',
    component: 'Input',
    required: false,
  },
  {
    field: 'telePhone',
    label: '应急电话',
    component: 'Input',
    required: false,
  },
  {
    field: 'nationality',
    label: '国籍',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return [2, 3, 4, 7].includes(model.identityType);
    },
  },
  {
    field: 'sex',
    label: '性别',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '女', value: 1 },
        { label: '男', value: 2 },
      ],
    },
    ifShow: ({ model }) => {
      return [2, 3, 4, 6, 7, 8].includes(model.identityType);
    },
  },
  {
    field: 'birthDate',
    label: '出生日期',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    field: 'issueAt',
    label: '证件签发地',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return [2, 3, 4, 7].includes(model.identityType);
    },
  },
  {
    field: 'expiryDate',
    label: '证件有效期',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
    ifShow: ({ model }) => {
      return [2, 3, 4, 7, 8].includes(model.identityType);
    },
  },
];

export const editYaokePrivateDataFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'userName',
    label: '姓名',
    component: 'Input',
    required: true,
  },
  {
    field: 'mobile',
    label: '会员手机号',
    component: 'Input',
    required: true,
  },
  {
    field: 'companyName',
    label: '公司名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'companyAddress',
    label: '公司地址',
    component: 'Input',
    required: false,
  },
  {
    field: 'telePhone',
    label: '应急电话',
    component: 'Input',
    required: false,
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    required: false,
  },
];

export const addCheckFormSchema: FormSchema[] = [
  {
    label: '用户物品Id',
    field: 'userGoodsId',
    component: 'Input',
    show: false,
    required: true,
  },
  {
    label: '使用类型',
    field: 'checkType',
    component: 'Input',
    show: false,
    defaultValue: 1,
    required: true,
  },
  {
    label: '操作类型',
    field: 'optType',
    component: 'Input',
    show: false,
    defaultValue: 1,
    required: true,
  },
  {
    label: '会员卡号',
    field: 'vipCardNo',
    component: 'Input',
    required: true,
    dynamicDisabled: true,
  },
  {
    label: '使用次数',
    field: 'useNum',
    component: 'InputNumber',
    defaultValue: 1,
    dynamicRules: () => rules.digits(true),
  },
  {
    label: '补录机场',
    field: 'airportId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: airportList,
        labelField: 'airportName',
        valueField: 'airportId',
        immediate: true,
        showSearch: true,
        onChange: airportId => {
          formModel.employeeId = null;
          formModel.employeeServerId = null;
        },
      };
    },
  },
  {
    label: '核验账号',
    field: 'employeeId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: employeeList,
        params: {
          airportId: formModel.airportId,
          handlerName: 'busEmployeeListHandler',
          haveHeYan: 1,
        },
        labelField: 'employeeAccountName',
        valueField: 'employeeId',
        showSearch: true,
        immediate: false,
        onChange: employeeId => {
          formModel.serverId = null;
        },
      };
    },
  },
  {
    label: '核销服务',
    field: 'employeeServerId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: employeeServerList,
        params: {
          employeeId: formModel.employeeId,
          serverType: 1,
        },
        labelField: 'serverName',
        valueField: 'employeeServerId',
        showSearch: true,
        immediate: false,
        onChange: employeeId => {},
      };
    },
  },
  {
    label: '使用时间',
    field: 'useDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      format: 'YYYY-MM-DD HH:mm:ss',
      disabledDate: current => {
        return current && current >= moment().add(0, 'day');
      },
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
  },
];

export const remarkFormSchema: FormSchema[] = [
  {
    label: '用户物品Id',
    field: 'userGoodsId',
    component: 'Input',
    show: false,
    required: true,
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
    componentProps: {
      autoSize: { minRows: 2, maxRows: 30 },
    },
  },
];

export const vipcardNoFormSchema: FormSchema[] = [
  {
    label: '用户物品Id',
    field: 'userGoodsId',
    component: 'Input',
    show: false,
    required: true,
  },
  {
    label: '原卡号',
    field: 'vipCardNo',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    label: '新卡号',
    field: 'newVipCardNo',
    component: 'Input',
    required: true,
  },
];

export const userGoodsChangeUserFormSchema: FormSchema[] = [
  {
    label: '用户物品Id',
    field: 'userGoodsId',
    component: 'Input',
    show: false,
    required: true,
  },
  {
    label: '选择换绑证明方式',
    field: 'modeType',
    component: 'RadioGroup',
    required: true,
    defaultValue: 2,
    dynamicDisabled: ({ values }) => {
      const regex = /^1[3-9]\d{9}$/;
      let isMobile = regex.test(values.mainAccount);
      if (isMobile) {
        return false;
      } else {
        return true;
      }
    },
    componentProps: {
      options: [
        { label: '原手机号验证码校验', value: 1 },
        { label: '上传申请函', value: 2 },
      ],
    },
  },
  {
    field: 'mainAccount',
    component: 'Input',
    label: '会员原账号',
    required: true,
    dynamicDisabled: true,
  },
  {
    label: '申请函证明',
    field: 'attachImg',
    component: 'ImageUpload',
    required: true,
    ifShow: ({ model }) => {
      if (model.modeType == 2) {
        return true;
      } else {
        return false;
      }
    },
  },

  {
    field: 'weChatId',
    label: '所属公众号',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: weChatList,
      labelField: 'weChatName',
      valueField: 'weChatId',
      showSearch: false,
      immediate: true,
    },
    ifShow: ({ model }) => {
      if (model.modeType == 1) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    field: 'changeUserMobileCode',
    component: 'InputCountNewDown',
    label: '验证码',
    required: true,
    componentProps: ({ formModel }) => {
      let params = { userGoodsId: formModel.userGoodsId, weChatId: formModel.weChatId };
      return {
        count: 120,
        sendCodeApi: getUserGoodsChangeUserMobileCode,
        params: params,
      };
    },
    ifShow: ({ model }) => {
      if (model.modeType == 1) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    field: 'newVipCardNo',
    label: '转卡新卡号',
    component: 'Input',
  },
  {
    field: 'mobile',
    label: '会员新手机账号',
    component: 'Input',
    rules: [
      { required: true, message: '请输入手机号' },
      { pattern: /^1[3456789]\d{9}$/, message: '手机号码格式错误！' },
    ],
  },
];

export const editUpgradeFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    label: '升降卡时间',
    field: 'upgradeDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      placeholder: '升降卡日期',
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      format: 'YYYY-MM-DD HH:mm:ss',
      disabledDate: current => {
        return current && current >= moment().add(0, 'day');
      },
    },
  },
];

export const fullDeductionFormSchema: FormSchema[] = [
  {
    label: '用户物品Id',
    field: 'userGoodsId',
    component: 'Input',
    show: false,
    required: true,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    label: '抵扣方式',
    field: 'fullDeductionType',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: listFullDeductionType,
        labelField: 'label',
        valueField: 'value',
        immediate: false,
        showSearch: true,
      };
    },
  },
  {
    label: '全额抵扣总金额(正数)',
    field: 'fullDeductionAmount',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '本次抵扣金额(负数)',
    field: 'thisDeductionAmount',
    component: 'InputNumber',
    required: true,
    componentProps: ({ formModel }) => {
      let fullDeductionAmount = formModel.fullDeductionAmount;
      return {
        max: 0,
        min: 0 - fullDeductionAmount,
      };
    },
    dynamicRules: ({ values }) => {
      return [
        { required: true, message: '请输入本次抵扣金额' },
        {
          validator: (_, value) => {
            if (typeof value === 'number' && value <= 0) {
              return Promise.resolve();
            }
            return Promise.reject(new Error('金额必须为负数或0'));
          },
        },
      ];
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
    componentProps: {
      maxlength: 100,
      autoSize: { minRows: 2, maxRows: 30 },
    },
  },
];

export const nowBackRecordFormSchema: FormSchema[] = [
  {
    label: '用户物品Id',
    field: 'userGoodsId',
    component: 'Input',
    show: false,
    required: true,
  },
  {
    field: 'payAmount',
    label: '支付金额',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '承担方式',
    field: 'bearWay',
    component: 'RadioGroup',
    required: true,
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '会员同意全部承担', value: 1 },
        { label: '会员不同意全部承担', value: 2 },
      ],
    },
  },
  {
    label: '会员承担金额',
    field: 'vipBearAmount',
    component: 'InputNumber',
    required: true,
    componentProps: ({ formModel }) => {
      let payAmount = formModel.payAmount;
      return {
        onChange: value => {
          console.info(payAmount);
          formModel.refundAmount = Number((Number(payAmount) - Number(value)).toFixed(2));
        },
      };
    },
  },
  {
    label: '销售承担金额',
    field: 'saleBearAmount',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '退款金额',
    field: 'refundAmount',
    component: 'InputNumber',
    required: true,
    componentProps: ({ formModel }) => {
      let payAmount = formModel.payAmount;
      return {
        onChange: value => {
          formModel.vipBearAmount = Number((Number(payAmount) - Number(value)).toFixed(2));
        },
      };
    },
  },
];
